{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "883f592c-8d54-47fb-9d6d-dd58d6a7af05",
   "metadata": {
    "tags": []
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Merged dataset saved to ../dataset/PestDetectionv5Dataset/csv/all/merged_dataset.csv\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import os\n",
    "\n",
    "# 指定包含 CSV 文件的文件夹路径\n",
    "folder_path = '../dataset/PestDetectionv5Dataset/csv/all'\n",
    "\n",
    "# 找到文件夹中所有的 CSV 文件\n",
    "csv_files = [os.path.join(folder_path, file) for file in os.listdir(folder_path) if file.endswith('.csv')]\n",
    "\n",
    "# 合并所有 CSV 文件\n",
    "all_data = pd.concat([pd.read_csv(file) for file in csv_files])\n",
    "\n",
    "\n",
    "# 保存到新的 CSV 文件\n",
    "merged_file_path = '../dataset/PestDetectionv5Dataset/csv/all/merged_dataset.csv'\n",
    "all_data.to_csv(merged_file_path, index=False)\n",
    "print(f\"Merged dataset saved to {merged_file_path}\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bc330c2b-6417-4766-9ae6-95c6bd7cb05e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
